// 获取product
var shop = document.querySelector("#shopping");

function getUrl(url){
    var urlArr = url.split("?")[1];
    console.log(urlArr);
    urlArr = urlArr.split("&");
    console.log(urlArr);

    var obj = {};
    urlArr.forEach(item => {
        var itemArr = item.split("=");
        obj[itemArr[0]] = itemArr[1];
    });
    return obj;
}
// 优惠券详情页
(function(){
    var urlstyring = decodeURI(location.href);
    console.log(urlstyring);

    let regExp = /(?<=imgurl=)[^'"]*/;
    var pObj = getUrl(urlstyring);
    console.log(pObj);

    const xhr = new XMLHttpRequest();
    xhr.open("get","http://chst.vip:1234/api/getcouponproduct?couponid="+pObj.couponid,true);
    xhr.send();
    xhr.onreadystatechange = function(){
         if(xhr.readyState === 4 && xhr.status === 200){
            var res = JSON.parse(xhr.responseText);
            console.log(res.result);
            var rex = res.result;
            var ele = "";
            rex.forEach(item => {
                ele += `
                <li class="photo">
                <div class="photo_left">
                ${item.couponProductImg}
                </div> 
                <div class="photo_right">
                <div class="photo_right_top">
            <span>${item.couponProductName}</span>
            <br>
            <span>${item.couponProductPrice}</span>
            <div class="photo_right_bottom">
            <span>${item.couponProductTime}</span>
        
        </div>
        </li>  
                `
            })
           
            shop.innerHTML = ele;
         }
        
    }
$("gotop").click(function(){
    $("body,html").animate({scrollTop:0},1000);
})
})();